package com.example.firstdemo.ui.screens.pages.addProblem.addProblemList

import androidx.lifecycle.ViewModel
import com.example.firstdemo.network.api.addProblem.AddProblemApi
import com.example.firstdemo.ui.screens.pages.addProblem.addProblemList.data.AddProblemListUIState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

class AddProblemListViewModel : ViewModel() {
    private val _uiState = MutableStateFlow(AddProblemListUIState())
    val uiState: StateFlow<AddProblemListUIState> = _uiState

    fun getProblemList() {
        CoroutineScope(Dispatchers.Main).launch {
            try {
                val problemList = AddProblemApi.getList().data!!
                _uiState.value = _uiState.value.copy(
                    problemList = problemList
                )
            } catch (_: Exception) {
            }
        }
    }
}